<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  //启动Worker子线程，并传入参数
  // var worker=new Worker('sub.js',{name:'john'})
  // //进行异常处理
  // worker.onerror=function (err) {
  //   console.log(err.message)
  // }

  //启动Worker子线程，并传入参数
  // var worker=new Worker('sub.js',{name:'john'})
  //
  // //父线程向子线程发送
  // worker.postMessage({name:"good js"})
  // //等待子线程发送过来的数据
  // worker.onmessage=function (event) {
  //   console.log(event.data)
  // }

  //子线程通信用的channel
  var channel=new MessageChannel();
  //分别启动两个子线程
  var worker1=new Worker('sub1.js')
  var worker2=new Worker('sub2.js')
  //将port1和port2分别传递给子线程
  worker1.postMessage({port:channel.port1},[channel.port1])
  worker2.postMessage({port:channel.port2},[channel.port2])
  

</script>
</body>
</html>
